<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%;"
  >
    <el-col :span="20"><span>{{ nodeData.name }}</span></el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <el-col>{{ nodeData.manager }}</el-col>
        <el-col>
          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link">
              操作<i class="el-icon-arrow-down el-icon--right" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="add">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!root" command="edit">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!root" command="del">删除部门</el-dropdown-item>

            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { reqDelDepartment } from '@/api/departments'
export default {
  props: {
    nodeData: {
      type: Object,
      required: true
    },
    root: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    handleCommand(command) {
      if (command === 'add') {
        console.log('添加', command)
        // console.log('小安我爱你，么么哒么么哒！')
        this.$emit('add-depts', this.nodeData)
      }
      if (command === 'edit') {
        console.log('编辑', command)
        this.$emit('emit-depts', this.nodeData)

        // this.$emit('emit-dept')
      }
      if (command === 'del') {
        console.log('删除', command)
        this.$confirm('此操作将永久删除该部门,继续吗?', '提示', { type: 'warning' }).then(async() => {
          const res = await reqDelDepartment(this.nodeData.id)
          console.log(res, 52)
          this.$message.success(res.message)
          this.$emit('del-dept')
        }).catch(() => {
          this.$message.success('已取消该操作')
        //   console.log('取消')
        })
      }
    }
  }

}
</script>

<style>

</style>
